﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using MockupDesigner.Items;
using MockupDesigner.AppItems;
using System.Windows.Controls;
using MockupDesigner.AppItems.Commands;

namespace MockupDesigner.Editors
{
    [AttributeUsage(AttributeTargets.Class)]
    public abstract class ItemEditor : Attribute
    {
        public ItemBase ItemToEdit { get; set; }

        public FrameworkElement Element { get; set; } // the element to display for edition

        public virtual void SetItem(ItemBase itemToEdit)
        {
            this.ItemToEdit = itemToEdit;
            DesignerItem parent = this.ItemToEdit.Parent as DesignerItem;
            if (this.Element != null)
            {
                this.Element.Height = parent.Height;
                this.Element.Width = parent.Width;
            }
        }

        public void LeaveFocus()
        {
            DesignerItem parent = ItemToEdit.Parent as DesignerItem;
            DesignerCanvas canvas = parent.Parent as DesignerCanvas;
            canvas.Focus();
            canvas.SelectionService.ClearSelection();
            canvas.SelectionService.SelectItem(parent);
        }
    }
}
